Skip to content

perf: Optimize NULL handling in StringViewArrayBuilder#21538

Merged
martin-g merged 5 commits intoapache:mainfrom
neilconway:neilc/perf-string-view-builder-nulls
Apr 14, 2026
Merged

perf: Optimize NULL handling in StringViewArrayBuilder#21538
martin-g merged 5 commits intoapache:mainfrom
neilconway:neilc/perf-string-view-builder-nulls

Conversation

@neilconway
Copy link
Copy Markdown
Contributor

@neilconway neilconway commented Apr 10, 2026

Which issue does this PR close?

Rationale for this change

StringViewArrayBuilder is implemented on top of Arrow's StringViewBuilder; the latter tracks NULLs incrementally. However, the StringViewArrayBuilder requires callers to pass a NULL buffer to finish() anyway, so the NULL bitmap that has been computed by StringViewBuilder is discarded. It would be more efficient to stop using StringViewBuilder so that we don't do this redundant work; in theory there might be room for inconsistency between the two NULL bitmaps as well.

Right now, StringViewArrayBuilder is only used by the concat and concat_ws UDFs, but I'd like to generalize the API and use it more broadly in place of StringViewBuilder (#21539). For the time being, here are the results of this PR on the concat benchmarks (Arm64):

  - 1024 rows: 29.6 µs → 28.0 µs, -5.3%
  - 4096 rows: 134.3 µs → 125.6 µs, -6.5%
  - 8192 rows: 289.7 µs → 273.5 µs, -5.6%

What changes are included in this PR?

  • Stop using StringViewBuilder and build the views ourselves
  • Improve some comments
  • Return an error instead of panicking on large input strings

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the functions Changes to functions implementation label Apr 10, 2026
@neilconway
Copy link
Copy Markdown
Contributor Author

FYI @Omega359

Copy link
Copy Markdown
Contributor

@Omega359 Omega359 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked this over and it seems reasonable, thanks!

@neilconway
Copy link
Copy Markdown
Contributor Author

@martin-g @timsaucer Thanks for the reviews! I noticed that the existing code panicked for large input strings, so I adjusted that to return an error (via Result) instead.

@alamb alamb added performance Make DataFusion faster api change Changes the API exposed to users of the crate labels Apr 13, 2026
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Apr 13, 2026

run benchmark concat

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4238361261-1168-r48dj 6.12.55+ #1 SMP Sun Feb 1 08:59:41 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing neilc/perf-string-view-builder-nulls (4e33f61) to 4389f14 (merge-base) diff
BENCH_NAME=concat
BENCH_COMMAND=cargo bench --features=parquet --bench concat
BENCH_FILTER=
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                               main                                   neilc_perf-string-view-builder-nulls
-----                               ----                                   ------------------------------------
concat function/concat/1024         1.00     15.5±0.43µs        ? ?/sec    1.00     15.6±0.42µs        ? ?/sec
concat function/concat/4096         1.00     62.4±1.73µs        ? ?/sec    1.01     62.9±1.63µs        ? ?/sec
concat function/concat/8192         1.00    124.3±3.55µs        ? ?/sec    1.00    123.8±3.78µs        ? ?/sec
concat function/concat/scalar       1.00   1013.8±5.36ns        ? ?/sec    1.01   1020.6±3.52ns        ? ?/sec
concat function/concat_view/1024    1.03     40.6±0.19µs        ? ?/sec    1.00     39.6±0.07µs        ? ?/sec
concat function/concat_view/4096    1.02    199.0±0.43µs        ? ?/sec    1.00    194.6±0.48µs        ? ?/sec
concat function/concat_view/8192    1.01    422.3±0.55µs        ? ?/sec    1.00    416.3±0.72µs        ? ?/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 69.1s
Peak memory 3.5 GiB
Avg memory 3.5 GiB
CPU user 85.6s
CPU sys 0.9s
Peak spill 0 B

branch

Metric Value
Wall time 68.7s
Peak memory 3.5 GiB
Avg memory 3.5 GiB
CPU user 86.1s
CPU sys 0.2s
Peak spill 0 B

File an issue against this benchmark runner

@neilconway
Copy link
Copy Markdown
Contributor Author

@martin-g Is this okay to merge?

@martin-g martin-g enabled auto-merge April 14, 2026 13:54
@martin-g martin-g added this pull request to the merge queue Apr 14, 2026
Merged via the queue into apache:main with commit 961c5fc Apr 14, 2026
31 checks passed
@neilconway
Copy link
Copy Markdown
Contributor Author

Thanks @martin-g @timsaucer !

}

pub fn append_offset(&mut self) {
pub fn append_offset(&mut self) -> Result<()> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an API change we should call out (I'll add a api-change label)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate functions Changes to functions implementation performance Make DataFusion faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize NULL handling in StringViewArrayBuilder

6 participants